package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.DueRemainderConfigService;
import com.yixun.qfbao.service.ModelService;
import com.yixun.qfbao.model.dto.DueRemainderConfigDto;
import com.yixun.qfbao.model.enums.ModelTypeEnum2;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.CompanyService;
import com.yixun.qfbao.apidto.GetAgencyIndexSwitchReqDto;
import com.yixun.qfbao.apidto.GetAgencyIndexSwitchResDto;
import com.yixun.qfbao.apidto.ModelResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.Company;
import com.yixun.qfbao.model.Model;
import com.yixun.qfbao.model.dto.CompanyDto;
import com.yixun.qfbao.vo.GetAgencyIndexSwitchReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * 
 *		
 */
@Service("getAgencyIndexSwitchHander")
public class GetAgencyIndexSwitchHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(GetAgencyIndexSwitchHander.class);
	
	@Autowired
	private CompanyService companyService;

	@Autowired
	private DueRemainderConfigService dueRemainderConfigService;
	
	@Autowired
	private ModelService modelService;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		GetAgencyIndexSwitchReqVo req = (GetAgencyIndexSwitchReqVo)reqDto;
		GetAgencyIndexSwitchReqDto reqDto1 = req.getParams();
		BaseResponseDTO<GetAgencyIndexSwitchResDto> res = new BaseResponseDTO<GetAgencyIndexSwitchResDto>();
		GetAgencyIndexSwitchResDto resDto = new GetAgencyIndexSwitchResDto();
		try {
            resDto = companyService.getAgencyIndexSwitch(reqDto1);

            /*add by zilong.liu 查询消息过期提醒的配置*/
			DueRemainderConfigDto dueRemainderConfigDto = new DueRemainderConfigDto();
			CompanyDto companyDto = new CompanyDto();
        	companyDto.setCompanyUuid(reqDto1.getCompanyUuid());
        	Company company = companyService.selectByDto(companyDto);
			dueRemainderConfigDto.setCompanyId(company.getId());
			resDto.setDueRemainderConfigDtoList(dueRemainderConfigService.getDueRemainderConfigList(dueRemainderConfigDto));
			/*add by zilong.liu 查询消息过期提醒的配置*/
			resDto.setEnableWeapp("1".equals(company.getEnableWeappMsg()));
			if("1".equals(company.getEnableWeappMsg())) {
				resDto.setEnableAgencyRegesit("1".equals(company.getEnableAgencyRegesit()));
				Model model = new Model();
				model.setType(ModelTypeEnum2.COMPANY.getNo());
				model.setCompanyId(company.getId());
//				model.setCreateUserId(userId);
				List<Model> modelList = modelService.selectListByDto(model);
				resDto.setModelResDtoList(ModelResDto.listConvertModelToModelResDto(modelList));
			}
			
			res.setResData(resDto);
			res.setResult(ResultEnum.SUCCESS.getNo());
		} catch (Exception e) {
			logger.error("GetAgencyIndexSwitchHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("楼盘列表获取失败!");
		}
		return res;
	}
	
}
